import { _decorator, Component, Node, EditBox, director } from 'cc';

const { ccclass, property } = _decorator;



@ccclass('loginSceneMgr')
export class loginSceneMgr extends Component {
    @property(Node) 
    public my_EditBox:Node

    start() {
        globalThis._eventTarget.on('login',this.onLoginMessage,this);
    }

    update(deltaTime: number) {
        
    }

    public onLoginBtnClicked(){
        let str = this.my_EditBox.getComponent(EditBox).string;
        let sendData;
        console.log('登陆按钮被点击了',str);
        switch(str){
            case'1':
                sendData = 666666;
                break;
            case'2':
                sendData = 666661;
                break;
            case'3':
            sendData = 666662;
                break;
            default:
                break;
        }
        globalThis._loginClientMgr._sendMessage('login',{id:sendData});
    }

    public onLoginMessage(data){
        console.log('处理玩家登陆消息');
        globalThis._userInfo.room_id = data.room_id;
        globalThis._userInfo.user_name = data.user_name;
        globalThis._userInfo.user_id = data.user_id;
        globalThis._userInfo.user_head_url = data.user_head_url;
        globalThis._userInfo.user_room_cards = data.user_room_cards;   
        //加载大厅场景
        director.loadScene("HallScene");
    }
}

